﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <link href="~/Content/layui/css/layui.css" rel="stylesheet" />
</head>
<body>
    <div>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn " lay-event="Add">添加</button>
            </div>
        </script>
        <table id="demoTreeTb"></table>
        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-xs" lay-event="add">添加</a>
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>
    </div>
    <script src="~/Content/layui/layui.js"></script>
    <script>
        layui.config({
            base: '/Content/layui/js/'
        }).use(['treeTable'], function () {
            var treeTable = layui.treeTable;
            var $ = layui.$;
            // 渲染树形表格
            var insTb = treeTable.render({
                elem: '#demoTreeTb',
                url: '/Module/GetModuleData',
                tree: {
                    iconIndex: 2,           // 折叠图标显示在第几列
                    isPidData: true,        // 是否是id、pid形式数据
                    idName: 'Id',  // id字段名称
                    pidName: 'ParentId'     // pid字段名称
                },
                cols: [[
                    { type: 'numbers' },
                    { type: 'checkbox' },
                    { field: 'ModuleName', title: '模块名' },
                    { field: 'ControllerName', title: '控制器名' },
                    { field: 'ActionName', title: '方法名' },
                    { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 300 }
                ]]
                , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            });



            //头工具栏事件
            treeTable.on('toolbar(demoTreeTb)', function (obj) {
                //var checkStatus = table.checkStatus(obj.config.id);
                switch (obj.event) {
                    case 'Add':
                        layer.open({
                            title: '添加'
                            , content: '/Module/Add'
                            , type: 2
                            , area: ['500px', '600px']
                        });
                        break;
                };
            });
            //监听行工具事件
            treeTable.on('tool(demoTreeTb)', function (obj) {
                var data = obj.data;
                //console.log(obj)
                if (obj.event === 'del') {
                    layer.confirm('真的删除行么', function (index) {
                        //obj.del();
                        layer.close(index);
                        $.post("/Module/Del", { id: data.Id }, function (res) {
                            if (res.Success) {
                                //obj.del();
                                treeTable.reload('demoTreeTb');
                                layer.msg(res.Message);
                            } else {
                                layer.msg(res.Message);
                            }
                        })
                    });
                } else if (obj.event === 'edit') {
                    layer.open({
                        title: '修改'
                        , content: '/Module/Update/' + data.Id
                        , type: 2
                        , area: ['500px', '600px']
                    });
                } else if (obj.event === 'add') {
                    layer.open({
                        title: '添加'
                        , content: '/Module/Add1/' + data.Id
                        , type: 2
                        , area: ['500px', '600px']
                    });
                }
            });


        });
    </script>
</body>
</html>
